#include <stdio.h>
#include <stdlib.h>
#define MAX_N 2000
typedef struct 
{
    int value;
    int original_index;
} Element;
int compare(const void *a, const void *b) 
{
    return ((Element *)a)->value - ((Element *)b)->value;
}
int main() 
{
    int n;
    while (scanf("%d", &n) == 1) 
	{
        Element arr[MAX_N];
        int visited[MAX_N] = {0};
        int i;
        for (i = 0; i < n; i++) 
		{
            scanf("%d", &arr[i].value);
            arr[i].original_index = i;
        }
        Element sorted[MAX_N];
        for (i = 0; i < n; i++) 
		{
            sorted[i] = arr[i];
        }
        qsort(sorted, n, sizeof(Element), compare);
        int target_indices[MAX_N];
        for (i = 0; i < n; i++) 
		{
            target_indices[sorted[i].original_index] = i;
        }
        int cycles = 0;
        for (i = 0; i < n; i++) 
		{
            if (!visited[i]) 
			{
                cycles++;
                int current = i;
                while (!visited[current]) 
				{
                    visited[current] = 1;
                    current = target_indices[current];
                }
            }
        }
        printf("%d\n", n - cycles);
    }
    return 0;
}
